//项目管理
import * as React from 'react';
import {
  TreeSelect,
  Modal,
  Row,
  Col,
  DatePicker,
  notification,
  Menu,
  Steps,
  Dropdown,
  Icon,
  Input,
  Table,
  Button,
  Form,
  InputNumber,
  Spin,
  Select
} from 'antd';
import Link from 'umi/link';
import axios from 'axios';
import Api from '../../services/apis';
import { connect } from 'dva';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import router from 'umi/router';

const confirm = Modal.confirm;
const { RangePicker } = DatePicker;
const Step = Steps.Step;
const FormItem = Form.Item;
const Option = Select.Option;

import moment from 'moment';
import 'moment/locale/zh-cn';

@connect(({ user, project, activities, chart, loading }) => ({
  currentUser: user.currentUser,
  currentUserLoading: loading.effects['user/fetchCurrent']
}))
class buildingManagement extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: '',
      tranUnits: '',
      pageSize: 5,
      current: 1,
      tableData: [],
      modalVisible: false,
      selectdIds: [],
      loading: false,
      modalVisible: false,
      province: [],
      city: [],
      area: [],
      ownerStatus: [],
      ownerType: [],
      signStatus: [],
      assetStatus: [],
      communitys: [],
      hookBuilds: [],

      showDownload: false,
      downloadName: '',
      downloadLink: '',
      startDownload: false,

    };
  }

  componentWillMount() {
    const that = this;

    //项目编码
    this.setState({
      projectId: this.props.location.query.id,
      projectName: this.props.location.query.projectName,
      communityName: this.props.location.query.communityName,
      manageType: this.props.location.query.manageType,
      transferUnit: this.props.location.query.transferUnit,
    }, () => {
      that.sendData();
    });

    //获取系统参数
    axios.all([this.getSysDic("OWNER_SHIP_STATUS"), this.getSysDic("OWNER_SHIP_TYPE"), this.getSysDic("SIGN_STATUS"), this.getSysDic("ASSET_STATUS")])
      .then(axios.spread(function (r1, r2, r3, r4) {
        that.setState({
          ownerStatus: r1.data, //权属权属状态
          ownerType: r2.data,  //权属形式
          signStatus: r3.data,  //签署协议状态
          assetStatus: r4.data,  //资产状态
        })
      }))

    this.getAreaList('1');
  }

  //获取省、市、区
  getAreaList = (level, areaId) => {
    const that = this;
    const param = { level: level };
    if (level !== '1') {
      param.id = areaId;
    }
    that.setState({ loading: true })
    return axios.post(Api.amGetAreaList, param)
      .then(function (resp) {
        const { data } = resp;
        if (level === '1') {
          that.setState({ province: data })
        } else if (level === '2') {
          that.setState({ city: data })
          that.props.form.setFieldsValue({
            city: '',
            area: ''
          })
        } else if (level === '3') {
          that.setState({ area: data })
          that.props.form.setFieldsValue({
            area: ''
          })
        }

        that.setState({ loading: false })
      })
  }

  //获取挂接楼栋下拉
  getHookBuildData = (communityId, buildingCode) => {
    const that = this;
    axios.post(Api.amGetHookBuildData, {
      communityId: communityId,
      buildingCode: buildingCode
    })
      .then(function (resp) {
        const { data } = resp;
        that.setState({ hookBuilds: data })
      })
  }

  ///获取系统参数
  getSysDic = (type) => {
    return axios.post(Api.amGetSysDic, { key: type })
  }

  //获取表格数据
  sendData = () => {
    let that = this;
    this.setState({ loading: true })
    axios.post(Api.amGetBuildList, {
      buildingName2: that.state.name,
      transferUnit: that.state.tranUnits,
      isRent: that.state.s_isRent,
      currentPage: that.state.current,
      projectCode: that.state.projectId
    })
      .then(function (resp) {
        const data = resp.data;
        if (data.list.length == 0) {
          notification.destroy();
          notification['warning']({
            message: '暂无数据',
          });
        }

        data.list.forEach((d, i) => {
          d.key = i;
          that.state.ownerType.forEach(item => {
            if (item.dicCode == d.ownershipType) {
              d.ownershipTypeText = item.dicName
            }
          })
        })
        that.setState({
          tableData: data.list,
          pageSize: data.pageSize,
          current: data.currentPage,
          total: data.totalSize
        })
        that.setState({ loading: false })
      })
  };

  //查询
  query = () => {
    this.setState({ current: 1 }, () => {
      this.sendData();
    });
  };

  //导出
  export = () => {
    if (this.state.selectdIds.length != 0) {
      const param = this.state.selectdIds.join(',');
      this.setState({
        startDownload: false
      });
      axios.get(Api.amExportBuild, {
        params: {
          buildCodes: param,
        },
        responseType: 'arraybuffer'
      }).then((res) => {
        notification.destroy();
        notification['success']({ message: '开始下载！' })

        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        const [dLink, name] = [
          window.URL.createObjectURL(blob),
          `楼栋列表${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}.xls`
        ];
        let link = document.createElement('a');
        link.href = dLink;
        link.download = name;
        link.click();
        this.setState({
          startDownload: true,
          downloadLink: dLink,
          downloadName: name,
          showDownload: true
        });
      }).catch((err) => {
        notification.destroy();
        notification['warning']({ message: `下载失败！错误信息：${err}` })
      });
    } else {
      notification.destroy();
      notification['warning']({ message: '请选择表格中的项后进行导出！' })
    }
  };

  showDownload(showDownload) {
    this.setState({ showDownload });
  }

  changeName = e => {
    this.setState({ name: e.target.value });
  };

  changeTranUnits = e => {
    this.setState({ tranUnits: e.target.value });
  };

  changeIsRent = value => {
    this.setState({ s_isRent: value });
  };

  pageChange = page => {
    this.setState(
      {
        current: page,
      },
      () => {
        this.sendData();
      }
    );
  };

  setAddProjectModalVisible = (visible) => {
    this.setState({ addProjectModalVisible: visible })
  }

  handleMenuClick = (building) => {
    var win = window.open(`/fe/assetMap/buildingDetails?buildingCode=${building.buildingCode}&buildingId=${building.buildingId}`, '_blank');
    win.focus();
  }

  //获取楼栋详情
  getBuildInfo = (item) => {
    const that = this;
    that.setState({ loading: true })
    axios.post(Api.amGetBuildInfo, { buildingCode: item.buildingCode })
      .then(function (resp) {
        const { data } = resp;
        that.setState({
          communityId: data.communityId,
          communityName: data.communityName,
          modalType: 'edit',
          projectCode: data.projectCode
        })

        that.props.form.setFieldsValue({
          buildingCode: data.buildingCode,
          buildingName2: data.buildingName2,
          communityName: data.communityName,
          houseCount: data.houseCount,
          receivedDate: data.receivedDate ? moment(data.receivedDate) : null,
          ownershipType: data.ownershipType,
          transferUnit: data.transferUnit,
          isRent: data.isRent,
          ownershipStatus: data.ownershipStatus,
          manageType: data.manageType,
          buildingStructure: data.buildingStructure,
          totalFloor: data.totalFloor,
          province: data.province,
          city: data.city,
          area: data.area,
          location: data.location,
          use: data.use,
          isSingle: data.isSingle
        })

        //赋值省市区联动
        that.getAreaList(2, data.province)
          .then(function () {
            that.props.form.setFieldsValue({ city: data.city })

            that.getAreaList(3, data.city)
              .then(function () {
                that.props.form.setFieldsValue({ area: data.area })
              })
          })

        that.setAddProjectModalVisible(true);
        that.setState({ loading: false })
      })
  }

  //编辑项目(点弹框确定)
  editBuilding = () => {
    let that = this;
    this.props.form.validateFields((err, values) => {
      this.setState({ loading: true })
      axios.post(Api.amUpdateBuildInfo, {
        buildingCode: values.buildingCode,
        buildingStructure: values.buildingStructure,
        buildingName2: values.buildingName2,
        projectCode: that.state.projectCode,
        communityId: that.state.communityId,
        communityName: that.state.communityName,
        totalFloor: values.totalFloor,
        ownershipType: values.ownershipType,
        use: values.use,
        province: values.province,
        city: values.city,
        area: values.area,
        location: values.location,
        isRent: values.isRent,
        isSingle: values.isSingle,
        buildingArea: values.buildingArea,
        landArea: values.landArea,
      })
        .then(function (resp) {
          const { data } = resp;
          if (data.code == 1) {
            notification.destroy();
            notification['success']({ message: data.msg });
            that.sendData();
            that.setAddProjectModalVisible(false);
          } else if (data.code == 0) {
            notification.destroy();
            notification['error']({ message: data.msg });
          }
          that.setState({ loading: false })
        })
    })
  };

  //新增、编辑
  modalSubmit = () => {
    if (this.state.modalType == 'edit') {
      //编辑
      this.editBuilding();
    } else {
      //新建
      this.addBuilding();
    }
  }

  addBuilding = () => {
    let that = this;
    this.props.form.validateFields((err, values) => {
      this.setState({ loading: true })
      axios.post(Api.amAddBuildInfo, {
        buildingStructure: values.buildingStructure,
        buildingArea: values.buildingArea,
        buildingCode: values.buildingCode,
        buildingName2: values.buildingName2,
        totalFloor: values.totalFloor,
        ownershipType: values.ownershipType,
        use: values.use,
        province: values.province,
        city: values.city,
        area: values.area,
        location: values.location,
        landArea: values.landArea,
        isRent: values.isRent,
        manageType: values.manageType,
        projectCode: that.state.projectId,
        isSingle: values.isSingle
      }).then(function (resp) {
        const { data } = resp;
        if (data.code == 1) {
          notification.destroy();
          notification['success']({ message: data.msg });
          that.sendData();
          that.setAddProjectModalVisible(false);
        } else if (data.code == 0) {
          notification.destroy();
          notification['error']({ message: data.msg });
        }
        that.setState({ loading: false });
      })
    })
  }

  //删除楼栋
  deleteBuilding = (id) => {
    const that = this;
    confirm({
      title: "删除确认",
      content: '确认删除该楼栋？',
      onOk() {
        that.setState({ loading: true })
        axios.post(Api.amDelBuildInfo, { buildingCode: id })
          .then(function (resp) {
            const { data } = resp;
            if (data.code == 1) {
              notification.destroy();
              notification['success']({ message: data.msg });
              that.sendData();
            } else {
              notification.destroy();
              notification['warning']({ message: data.msg });
            }
            that.setState({ loading: false })
          })
      }
    })
  }

  changeSelected = (selectedRowKeys, selectedRows) => {
    let selectdIds = [];
    selectedRows &&
      selectedRows.forEach((d, i, arr) => {
        selectdIds.push(d.buildingCode);
      });

    this.setState({ selectedArr: selectedRowKeys, selectdIds: selectdIds });
  };

  openAddModal = () => {
    this.setState({ addProjectModalVisible: true }, () => {
      this.setState({ modalType: 'new' })
      this.props.form.setFieldsValue({
        communityName: this.state.communityName != 'null' ? this.state.communityName : '',
        manageType: this.state.manageType != 'null' ? this.state.manageType : '',
        transferUnit: this.state.transferUnit != 'null' ? this.state.transferUnit : '',
        ownershipStatus: '40',
        buildingCode: '',
        buildingName2: '',
        houseCount: '',
        receivedDate: '',
        ownershipType: '',
        isRent: '',
        use: '',
        buildingStructure: '',
        buildingArea: '',
        landArea: '',
        totalFloor: '',
        province: '',
        city: '',
        area: '',
        location: '',
        isSingle: ''
      })
    })
  }

  openEditModal = (item) => {
    //获取楼栋详情
    this.getBuildInfo(item);
  }

  render() {
    let that = this;
    const { form: { getFieldDecorator }, currentUserLoading } = this.props;
    //表格表头
    let columns = [
      {
        title: '楼栋名称',
        dataIndex: 'buildingName2',
        key: 'buildingName2',
        render: (text, item, index) => (
          <a href="javascrip:;" onClick={this.handleMenuClick.bind(this, item)}>
            {text}
          </a>
        ),
      },
      {
        title: '楼栋编号',
        dataIndex: 'buildingCode',
        key: 'buildingCode',
      },
      {
        title: '挂接楼盘',
        dataIndex: 'communityName',
        key: 'communityName',
      },
      {
        title: '租赁状态',
        dataIndex: 'isRent',
        key: 'isRent',
      },
      {
        title: '权属形式',
        dataIndex: 'ownershipTypeText',
        key: 'ownershipTypeText',
      },
      {
        title: '建筑结构',
        dataIndex: 'buildingStructure',
        key: 'buildingStructure',
      },
      {
        title: '总层数',
        dataIndex: 'totalFloor',
        key: 'totalFloor',
      },
      {
        title: '房间数',
        dataIndex: 'houseCount',
        key: 'houseCount',
        render: (text, item, index) => {
          return text == 0 ? 0 :
            (
              <Link
                key={index}
                target='_blank'
                to={{
                  pathname: '/fe/assetManagement/houseManagement',
                  search: `?buildingCode=${item.buildingCode}&projectCode=${this.state.projectId}&projectName=${this.state.projectName}&manageType=${this.state.manageType}&transferUnit=${this.state.transferUnit}&obtainWay=${item.obtainWay}&ownershipType=${item.ownershipType}&buildingName2=${item.buildingName2}`
                }}>{text}</Link>
            )
        }
      },
      {
        title: '操作',
        dataIndex: 'action',
        key: 'action',
        render: (text, item, index) => (
          <span>
            <a href="javascript:;" onClick={this.getBuildInfo.bind(this, item)}>编辑</a>&emsp;
            <a href="javascript:;" onClick={this.deleteBuilding.bind(this, item.buildingCode)}>删除</a>
          </span>
        ),
      },
    ];

    if (this.props.location.state !== undefined && this.props.location.state.fromHomepage) {
      columns.unshift({
        title: '项目名称',
        dataIndex: 'project_name',
        key: 'project_name',
      });
    }

    const rowSelection = {
      selectedRowKeys: this.state.selectedArr,
      onChange: (selectedRowKeys, selectedRows) => {
        this.changeSelected(selectedRowKeys, selectedRows);
      },
    };

    return (
      <PageHeaderWrapper
        loading={currentUserLoading}
      >

        <div className="mainContainer">
          <div className='contentHeader'>
            <div className="contentHeaderTitle">
              <p>楼栋管理</p>
              <p>BUILDING MANAGEMENT</p>
            </div>
          </div>
          <div className='mrb15'>
            <Form layout="inline" align='center'>
              <FormItem>
                <span className="label">楼栋名称</span>
                <Input
                  value={this.state.name}
                  data-inp="zdbh"
                  onChange={this.changeName}
                  placeholder="请输入楼栋名称"
                />
              </FormItem>

              <FormItem>
                <span className="label">划转单位</span>
                <Input
                  value={this.state.tranUnits}
                  data-inp="zdbh"
                  onChange={this.changeTranUnits}
                  placeholder="请输入划转单位"
                />
              </FormItem>

              <FormItem>
                <span className="label">租赁状态</span>
                <Select placeholder="请选择租赁状态" value={this.state.s_isRent} onChange={(value) => this.changeIsRent(value)}>
                  <Option value=''>&emsp;</Option>
                  <Option value='已租赁'>已租赁</Option>
                  <Option value='待租赁'>待租赁</Option>
                </Select>
              </FormItem>

              <Row gutter={24} style={{ textAlign: 'center' }}>
                <Button icon="search" type="primary" className="evfilterbtn" onClick={this.query}>
                  搜索
                  </Button>
                &emsp;
                  <Button icon="plus-circle"
                  onClick={() => this.openAddModal(true)}
                  type="primary"
                  htmlType="reset"
                  className="evfilterbtn"
                >
                  新增楼栋
                  </Button>
                &emsp;
                  <Button icon='profile' ghost
                  onClick={this.export}
                  type="primary"
                  htmlType="reset"
                  className="evfilterbtn"
                >
                  生成报表
                  </Button>
              </Row>
            </Form>
          </div>

          <Spin spinning={this.state.loading}>
            <Row>
              <Table
                bordered={true}
                scroll={{ x: true }}
                columns={columns}
                dataSource={this.state.tableData}
                rowSelection={rowSelection}
                pagination={{
                  defaultPageSize: that.state.pageSize,
                  current: that.state.current,
                  onChange: that.pageChange,
                  total: that.state.total,
                  showTotal: total => `共 ${total} 项`
                }}
              />
            </Row>

            <Modal
              title={this.state.modalType == 'edit' ? "编辑楼栋" : "新增楼栋"}
              visible={this.state.addProjectModalVisible}
              width={830}
              onOk={this.modalSubmit}
              onCancel={() => this.setAddProjectModalVisible(false)}
            >
              <Row gutter={24}>
                <Col span={8}>
                  <FormItem label="楼栋编号：">
                    {getFieldDecorator('buildingCode', {
                      rules: [{ required: true, message: '请输入楼栋编号！' }]
                    })(<Input placeholder="请输入楼栋编号" disabled={this.state.modalType == "edit" ? true : false} />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="楼栋名称：">
                    {getFieldDecorator('buildingName2', {
                      rules: [{ required: true, message: '请输入楼栋名称！' }]
                    })(<Input placeholder="请输入楼栋名称" />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="小区名称：">
                    {getFieldDecorator('communityName')(<Input placeholder="请输入小区名称" disabled />)}
                  </FormItem>
                </Col>
                <Col span={8} style={{ display: this.state.modalType == "new" ? 'none' : 'inline-block' }}>
                  <FormItem label="房屋数量：">
                    {getFieldDecorator('houseCount', {
                      rules: [{ pattern: /^\d*$/, message: '请输入数值！' }]
                    })(<Input disabled />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="接管时间：">
                    {getFieldDecorator('receivedDate')(<DatePicker disabled style={{ width: "100%" }} />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="权属形式：">
                    {getFieldDecorator('ownershipType')(<Select placeholder="请择权属形式" style={{ width: "100%" }}>
                      {
                        this.state.ownerType.map(item =>
                          <Option key={item.dicCode} value={item.dicCode}>{item.dicName}</Option>)
                      }
                    </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="划转单位：">
                    {getFieldDecorator('transferUnit', {
                      rules: [{ required: true, message: '请输入划转单位！' }]
                    })(<Input placeholder="请输入划转单位" disabled />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="租赁状态：">
                    {getFieldDecorator('isRent', {
                      rules: [{ required: true, message: '请选择租赁状态！' }]
                    })(<Select placeholder="请选择租赁状态" style={{ width: '100%' }} disabled={this.props.form.getFieldValue('isSingle') == '1' ? false : true}>
                      <Option value='已租赁'>已租赁</Option>
                      <Option value='待租赁'>待租赁</Option>
                    </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="权属状态：">
                    {getFieldDecorator('ownershipStatus')(
                      <Select placeholder="请选择权属状态" disabled style={{ width: "100%" }}>
                        {
                          this.state.ownerStatus.map((item, i) =>
                            <Option key={item.dicCode} value={item.dicCode}>{item.dicName}</Option>)
                        }
                      </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="管理方式：">
                    {getFieldDecorator('manageType')(
                      <Select placeholder="请选择管理方式" style={{ width: "100%" }} disabled>
                        <Option value='自管'>自管</Option>
                        <Option value='托管'>托管</Option>
                      </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="用途：">
                    {getFieldDecorator('use', {
                      rules: [{ required: true, message: '请选择用途！' }]
                    })(
                      <Select placeholder="请选择用途" style={{ width: "100%" }}>
                        <Option value='保障性住房'>保障性住房</Option>
                        <Option value='公房'>公房</Option>
                        <Option value='学校宿舍'>学校宿舍</Option>
                        <Option value='普通住宅'>普通住宅</Option>
                        <Option value='临建房'>临建房</Option>
                        <Option value='车库'>车库</Option>
                      </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="建筑结构：">
                    {getFieldDecorator('buildingStructure')(
                      <Select placeholder="请选择建筑结构" style={{ width: "100%" }}>
                        <Option value="砖木结构">砖木结构</Option>
                        <Option value="混合结构">混合结构</Option>
                        <Option value="钢筋混凝土结构">钢筋混凝土结构</Option>
                        <Option value="钢结构">钢结构</Option>
                      </Select>)}
                  </FormItem>
                </Col>
                <Col span={8} style={{ display: (this.state.modalType == "new" || this.props.form.getFieldValue('isSingle') == '1') ? 'inline-block' : 'none' }}>
                  <FormItem label="建筑面积：">
                    {getFieldDecorator('buildingArea', {
                      rules: [{ required: true, message: '请输入建筑面积！' },
                      { pattern: /^[0-9]+([.]{1}[0-9]+){0,1}$/, message: '请输入数值！' }]
                    })(<Input placeholder="请输入建筑面积" />)}
                  </FormItem>
                </Col>
                <Col span={8} style={{ display: (this.state.modalType == "new" || this.props.form.getFieldValue('isSingle') == '1') ? 'inline-block' : 'none' }}>
                  <FormItem label="土地面积：">
                    {getFieldDecorator('landArea', {
                      rules: [{ required: true, message: '请输入土地面积！' },
                      { pattern: /^[0-9]+([.]{1}[0-9]+){0,1}$/, message: '请输入数值！' }]
                    })(<Input placeholder="请输入土地面积" />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="总层数：">
                    {getFieldDecorator('totalFloor', {
                      rules: [{ required: true, message: '请输入总层数！' },
                      { pattern: /^\d*$/, message: '请输入数值！' }]
                    })(<Input placeholder="请输入总层数" />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="所在省份：">
                    {getFieldDecorator('province', {
                      rules: [{ required: true, message: '请选择所在省份！' }]
                    })(<Select
                      showSearch style={{ width: '100%' }}
                      placeholder="请选择所在省份"
                      optionFilterProp="children"
                      onChange={(e) => this.getAreaList('2', e)}
                      filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                      disabled={this.state.modalType == "edit" ? true : false}
                    >{
                        this.state.province.map(item =>
                          <Option key={item.areaId} value={item.name}>{item.name}</Option>
                        )
                      }
                    </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="所在市：" style={{ textAlign: 'left' }}>
                    {getFieldDecorator('city', {
                      rules: [{ required: true, message: '请选择所在市！' }]
                    })(<Select
                      showSearch style={{ width: '100%' }}
                      placeholder="请选择所在市"
                      optionFilterProp="children"
                      onChange={(e) => this.getAreaList('3', e)}
                      filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                      disabled={this.state.modalType == "edit" ? true : false}
                    >{
                        this.state.city.map(item =>
                          <Option key={item.areaId} value={item.name}>{item.name}</Option>
                        )
                      }
                    </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="所在区：">
                    {getFieldDecorator('area', {
                      rules: [{ required: true, message: '请选择所在区！' }]
                    })(<Select
                      showSearch style={{ width: '100%' }}
                      placeholder="请选择所在区"
                      optionFilterProp="children"
                      filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                      disabled={this.state.modalType == "edit" ? true : false}
                    >{
                        this.state.area.map(item =>
                          <Option key={item.areaId} value={item.name}>{item.name}</Option>
                        )
                      }
                    </Select>)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="详细地址：">
                    {getFieldDecorator('location', {
                      rules: [{ required: true, message: '请输入详细地址！' }]
                    })(<Input placeholder="请输入详细地址" />)}
                  </FormItem>
                </Col>
                <Col span={8}>
                  <FormItem label="整栋接管：">
                    {getFieldDecorator('isSingle', {
                      rules: [{ required: true, message: '请选择整栋接管！' }]
                    })(<Select placeholder="请选择整栋接管" style={{ width: "100%" }}>
                      <Option value='1'>是</Option>
                      <Option value='0'>否</Option>
                    </Select>)}
                  </FormItem>
                </Col>
              </Row>
            </Modal>


            <Modal
              title="开始下载"
              visible={this.state.showDownload}
              width={400}
              wrapClassName="vertical-center-modal"
              onOk={this.showDownload.bind(this, false, 'ok')}
              onCancel={this.showDownload.bind(this, false, 'cancel')}
              style={{
                textAlign: 'center'
              }}
            >
              {this.state.downloadName !== '' ?
                <div>
                  <p>开始自动下载...</p>
                  <p><a download={this.state.downloadName} href={this.state.downloadLink}>下载没有开始，点击此链接手动下载。</a></p>
                </div>
                :
                <div>
                  <p>文件生成中，请稍后。</p>
                  <p><Icon type="loading" /></p>
                </div>
              }
            </Modal>

          </Spin>
        </div>
      </PageHeaderWrapper>
    );
  }
}

const WrappedApp = Form.create()(buildingManagement);
export default WrappedApp;
